home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
lang
/
fpcsrc.lha
/
fpc
/
compiler
/
radi386.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-09-24
|
13KB
|
301 lines
{
$Id: radi386.pas,v 1.1.1.1 1998/03/25 11:18:15 root Exp $
Copyright (c) 1998 by Florian Klaempfl
Reads inline assembler and writes the lines direct to the output
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
unit radi386;
interface
uses
tree;
function assemble : ptree;
implementation
uses
i386,hcodegen,globals,scanner,aasm,
cobjects,symtable,types,verbose,asmutils;
function assemble : ptree;
var
retstr,s,hs : string;
c : char;
ende : boolean;
sym : psym;
code : paasmoutput;
l : longint;
procedure writeasmline;
var
i : longint;
begin
i:=length(s);
while (i>0) and (s[i] in [' ',#9]) do
dec(i);
s[0]:=chr(i);
if s<>'' then
code^.concat(new(pai_direct,init(strpnew(s))));
{ if function return is param }
{ consider it set if the offset was loaded }
if assigned(procinfo.retdef) and
ret_in_param(procinfo.retdef) and
(pos(retstr,upper(s))>0) then
procinfo.funcret_is_valid:=true;
s:='';
end;
begin
ende:=false;
s:='';
if assigned(procinfo.retdef) and
(procinfo.retdef<>pdef(voiddef)) then
retstr:=upper(tostr(procinfo.retoffset)+'('+att_reg2str[procinfo.framepointer]+')')
else
retstr:='';
c:=asmgetchar;
code:=new(paasmoutput,init);
while not(ende) do
begin
case c of
'A'..'Z','a'..'z','_' : begin
hs:='';
while ((ord(c)>=ord('A')) and (ord(c)<=ord('Z')))
or ((ord(c)>=ord('a')) and (ord(c)<=ord('z')))
or ((ord(c)>=ord('0')) and (ord(c)<=ord('9')))
or (c='_') do
begin
inc(byte(hs[0]));
hs[length(hs)]:=c;
c:=asmgetchar;
end;
if upper(hs)='END' then
ende:=true
else
begin
if c=':' then
begin
getsym(upper(hs),false);
if srsym<>nil then
Message(assem_w_using_defined_as_local);
end;
if upper(hs)='FWAIT' then
FwaitWarning
else
{ access to local variables }
if assigned(aktprocsym) then
begin
{ is the last written character an special }
{ char ? }
if (s[length(s)]<>'%') and
(s[length(s)]<>'$') then
begin
if assigned(aktprocsym^.definition^.localst) then
sym:=aktprocsym^.definition^.localst^.search(upper(hs))
else
sym:=nil;
if assigned(sym) then
begin
if sym^.typ=varsym then
begin
{variables set are after a comma }
{like in movl %eax,I }
if pos(',',s) > 0 then
pvarsym(sym)^.is_valid:=1
else
if (pos('MOV',upper(s)) > 0) and (pvarsym(sym)^.is_valid=0) then
Message1(sym_n_local_var_not_init_yet,hs);
hs:='-'+tostr(pvarsym(sym)^.address)+'('+att_reg2str[procinfo.framepointer]+')';
end
else
{ call to local function }
if (sym^.typ=procsym) and (pos('CALL',upper(s))>0) then
begin
hs:=pprocsym(sym)^.definition^.mangledname;
end;
end
else
begin
if assigned(aktprocsym^.definition^.parast) then
sym:=aktprocsym^.definition^.parast^.search(upper(hs))
else
sym:=nil;
if assigned(sym) then
begin
if sym^.typ=varsym then
begin
l:=pvarsym(sym)^.address;
{ set offset }
inc(l,aktprocsym^.definition^.parast^.call_offset);
hs:=tostr(l)+'('+att_reg2str[procinfo.framepointer]+')';
if pos(',',s) > 0 then
pvarsym(sym)^.is_valid:=1;
end;
end
{ I added that but it creates a problem in line.ppi
because there is a local label wbuffer and
a static variable WBUFFER ...
what would you decide, florian ?
else
begin
getsym(upper(hs),false);
sym:=srsym;
if assigned(sym) and (sym^.typ = varsym)
or (sym^.typ = typedconstsym) then
hs:=sym^.mangledname;
if (sym^.typ=procsym) and (pos('CALL',upper(s))>0) then
begin
if assigned(pprocsym(sym)^.definition^.nextoverloaded) then
begin
exterror:=strpnew(' calling an overloaded procedure in asm');
warning(user_defined);
end;
h